package com.atguigu.lease.common.exception;

import com.atguigu.lease.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author liangtianzhe
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    public Result error(Exception e) {
        log.error("系统异常:",e);
        return Result.fail();
    }

    @ExceptionHandler(value = BusinessException.class)
    public Result businessException(BusinessException e){
        log.error("业务异常:",e);
        return Result.fail(e.getCode(),e.getMessage());
    }
}
